package cn.jboa.dao.impl;

import cn.jboa.dao.EmployeeDao;
import cn.jboa.entity.SysEmployee;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("employeeDao")
public class EmployeeDaoImpl extends HibernateDaoSupport implements EmployeeDao {
    public EmployeeDaoImpl(){ }
    @Autowired
    public EmployeeDaoImpl(@Qualifier("sessionFactory")SessionFactory sessionFactory){
       setSessionFactory(sessionFactory);
    }
    @Override
    public SysEmployee login(SysEmployee employee) {
        System.out.println(employee.toString());
        String hql = "from SysEmployee where sn=? and password=?";
        List<SysEmployee> list  = this.getHibernateTemplate().find(hql,employee.getSn(),employee.getPassword());
        if(list.size() > 0 ){
            return list.get(0);
        }else{
            return new SysEmployee();
        }
    }
}
